import { defineStore } from "pinia";
import { ref } from "vue";
import { fetchUserInfo } from '@/api/user'

export const useUserStore = defineStore('user', () => {
    const info = ref({} as UserInfo)
    const device = ref('')

    function handleGetUserInfo() {
        fetchUserInfo({ deviceInfo: device.value }).then(res => {
            if (res.data.code === 0) {
                info.value = res.data.data
            }
        }).catch(err => {
            throw new Error(err)
        })
    }

    return { info, device, handleGetUserInfo }
}, { persist: true })